#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/wait.h>

#define NUM 16

int main(int argc,char* argv[],char* env[])
{
    char* const _env[NUM] = {
        (char*)"SSH_VAL=666666666",
        NULL 
    };

    pid_t id = fork();

    if(id == 0)
    {
        printf("子进程开始运行，%d\n",getpid());
        sleep(3);
        execle("./test","test","-a",NULL,_env);

        // execl("./test","test","-b",NULL);
       
        // char *const _argv[NUM]= {
        //     (char*)"ls",
        //     (char*)"-a",
        //     (char*)"-l",
        //     NULL
        // };
        // execv("/usr/bin/ls",_argv);
           
        // execlp("ls","ls","--color=auto","-a","-l",NULL);
        // execvp("ls",_argv); 
        exit(1);
    }
    else
    {
        printf("子进程开始运行，%d\n",getpid());

        int status = 0;
        pid_t id = waitpid(-1,&status,0);

        if(id>0)
        {
            printf("wait success,exit code:%d\n",WEXITSTATUS(status));
        }
    }
        
    return 0;
}
